package xj.model.uml;

import static xj.model.uml.UMLModelConstants.ATTR_BODY;
import static xj.model.uml.UMLModelConstants.ATTR_LANG;

public class Action extends NamedElement {

  public Action() {
    this(null, null, null);
  }

  public Action(String name) {
    this(name, null, null);
  }

  public Action(String name, String lang, String body) {
    super(name);
    setLang(lang);
    setBody(body);

    destructable = false;
    preserved = true;
  }

  public String getLang() {
    return lang;
  }

  public void setLang(String lang) {
    this.lang = lang;
    setAttribute(ATTR_LANG, lang);
  }

  public String getBody() {
    return body;
  }

  public void setBody(String body) {
    this.body = body;
    setAttribute(ATTR_BODY, body);
  }

  @Override
  public String toString() {    
    //return (name != null ? (name +": ") : "") + (body != null ? body : "");
    return body; 
  }

  public String toLongString() {
    return "Action: name=" + name  + " lang=" + lang + " body=" + body;
  }

  @Override
  protected boolean asElement(String attrName) {
    if (attrName != null) {
      return (attrName.equals(ATTR_BODY));
    }
    return false;
  }

  @Override
  protected boolean inCDATASection(String name) {
    return asElement(name);
  }

  @Override
  public Object clone() throws CloneNotSupportedException {
    Action a = (Action) super.clone();
    a.setLang(lang);
    a.setBody(body);
    return a;
  }

  protected String lang;

  protected String body;

}
